package leetcode.code2380;

import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import leetcode.helper.H;

public class Solution {
	public int secondsToRemoveOccurrences(String s) {
		int z = s.charAt(0) == '0' ? 1 : 0;
		int o = 0;
		int ans = 0;
		for (int i = 1; i < s.length(); i++) {
			char c = s.charAt(i);
			z += c == '0' ? 1 : 0;
			if (c == '1' && s.charAt(i - 1) == '1' && z > 0) {
				o++;
			}
			if (c == '0' && s.charAt(i - 1) == '0' && o > 0) {
				o--;
			}
			if (c == '1' && z > 0) {
				ans = o + z;
			}
		}
		return ans;
	}

	public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException {
		Solution so = new Solution();
		so.secondsToRemoveOccurrences("10100011010010010101011011001111110");
//		so.secondsToRemoveOccurrences("1000111111");
		// 1000111111
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 35; i++) {
			int random = (int) (Math.random() * 2);
			if (random == 0) {
				sb.append('0');
			} else if (random == 1) {
				sb.append('1');
			} else {
				sb.append('?');
			}
		}
		System.out.println(sb.toString());
		Integer num = null;
		List<Integer> list = new ArrayList<>();
		list.add(1);
		list.add(2);
		for(int i : list) {
			System.out.println(i);
		}
		System.out.println(list);
//		System.out.println(num > 0);
		Map<String, String> map = new HashMap<>(4);
		Solution.Node node = so.new Node();
		node.getClass().getDeclaredMethod("hello", String.class).invoke(node, "world");
		System.out.println(1.4+1.1);
//		Path.of(null, args) 
	
	}

	public class Node {

		public Node() {

		}

		public void hello(String param) {
			System.out.println(param);
		}
	}
}
